import tkinter as tk

# 创建主窗口
root = tk.Tk()

# 隐藏窗口边框
root.overrideredirect(True)

# 设置窗口背景颜色为白色
root.configure(background="white")

# 创建标签，显示文本为 "16"，背景颜色为白色
label = tk.Label(root, text="16", bg="white", font=("Helvetica", 24))
label.pack(padx=20, pady=20)  # 设置标签的边距

# 鼠标按下时的初始位置和窗口位置
start_x, start_y = 0, 0
win_x, win_y = 0, 0

# 定义窗口边缘的宽度
edge_width = 8

# 检查鼠标是否在窗口边缘
def check_edge(event):
    x, y = event.x, event.y
    width = root.winfo_width()
    height = root.winfo_height()
    if x < edge_width and 0 < y < height:  # 左边缘
        return "left"
    elif x > width - edge_width and 0 < y < height:  # 右边缘
        return "right"
    elif y < edge_width and 0 < x < width:  # 上边缘
        return "top"
    elif y > height - edge_width and 0 < x < width:  # 下边缘
        return "bottom"
    else:
        return None

# 鼠标进入窗口边缘时改变鼠标样式
def on_edge(event):
    if check_edge(event):
        root.config(cursor="size_ns")
    else:
        root.config(cursor="")

# 鼠标按下事件处理函数
def on_mouse_press(event):
    global start_x, start_y, win_x, win_y
    start_x = event.x_root
    start_y = event.y_root
    win_x = root.winfo_x()
    win_y = root.winfo_y()

# 鼠标拖动事件处理函数
def on_mouse_drag(event):
    global start_x, start_y, win_x, win_y
    if check_edge(event):
        direction = check_edge(event)
        if "left" in direction:
            new_width = win_x + (event.x_root - start_x)
            new_x = win_x + (event.x_root - start_x)
            root.geometry(f"{new_width}x{root.winfo_height()}+{new_x}+{win_y}")
        if "right" in direction:
            new_width = root.winfo_width() + (event.x_root - start_x)
            root.geometry(f"{new_width}x{root.winfo_height()}+{win_x}+{win_y}")
        if "top" in direction:
            new_height = win_y + (event.y_root - start_y)
            new_y = win_y + (event.y_root - start_y)
            root.geometry(f"{root.winfo_width()}x{new_height}+{win_x}+{new_y}")
        if "bottom" in direction:
            new_height = root.winfo_height() + (event.y_root - start_y)
            root.geometry(f"{root.winfo_width()}x{new_height}+{win_x}+{win_y}")
    else:
        new_x = win_x + (event.x_root - start_x)
        new_y = win_y + (event.y_root - start_y)
        root.geometry(f"+{new_x}+{new_y}")

# 鼠标释放事件处理函数
def on_mouse_release(event):
    pass

# 绑定鼠标事件
root.bind("<Enter>", on_edge)
root.bind("<Button-1>", on_mouse_press)
root.bind("<B1-Motion>", on_mouse_drag)
root.bind("<ButtonRelease-1>", on_mouse_release)

# 进入主事件循环
root.mainloop()